package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.ClubTypeDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.ClubType;
import com.zy.pojo.query.bs.ClubTypeQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.ClubTypeService;
import com.zy.utils.DateUtil;

@Service("clubTypeService")
public class ClubTypeServiceImpl extends BaseServiceImpl<ClubType> implements ClubTypeService {

	@Autowired
	private ClubTypeDao clubTypeDao;

	@Override
	public PageVo pageClubType(ClubTypeQuery clubTypeQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.clubTypeDao.countClubType(clubTypeQuery), this.clubTypeDao.listClubType(clubTypeQuery, start, limit));
	}

	@Override
	public void saveClubType(ClubType clubType) {
		clubType.setId(null);
		long time = DateUtil.getTime();
		clubType.setCreateTime(time);
		clubType.setModifyTime(time);
		clubType.setStatus(StatusEnum.NORMAL.getValue());
		this.clubTypeDao.save(clubType);
	}
	
	@Override
	public void updateClubType(ClubType clubType) {
		clubType.setModifyTime(DateUtil.getTime());
		this.clubTypeDao.updateByPrimaryKeySelective(clubType);
	}

	@Override
	public void removeClubType(long id) {
		try {
			this.clubTypeDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			ClubType clubType = new ClubType();
			clubType.setId(id);
			clubType.setModifyTime(DateUtil.getTime());
			clubType.setStatus(StatusEnum.DELETE.getValue());
			this.clubTypeDao.updateByPrimaryKeySelective(clubType);
		}
	}

	@Override
	public void recover(long id) {
		ClubType clubType = new ClubType();
		clubType.setId(id);
		clubType.setModifyTime(DateUtil.getTime());
		clubType.setStatus(StatusEnum.NORMAL.getValue());
		this.clubTypeDao.updateByPrimaryKeySelective(clubType);
	}

}
